﻿Imports System.Linq
Imports Aricie.DNN.Services.Url.FriendlyUrl.Controls.GroupEntities

Namespace Aricie.DNN.Services.Url.FriendlyUrl.Controls.GroupManagement

    Public Class FUPGroupManagerFactory
        Private Shared ManagerFactories As New Dictionary(Of String, IFUPGroupManager)
        Shared Sub New()

            Dim ListOfGroupManagers As IFUPGroupManager() = New IFUPGroupManager() {New UrlPartGroupManager(), New AliasUrlGroupManager(), New QueryStringUrlGroupManager(), New ProviderUrlGroupManager()}

            For Each GroupManager As IFUPGroupManager In New IFUPGroupManager() {New UrlPartGroupManager(), _
                                                                                 New AliasUrlGroupManager(), _
                                                                                 New QueryStringUrlGroupManager(), _
                                                                                 New ProviderUrlGroupManager(), _
                                                                                 New ConstantUrlGroupManager()}
                ManagerFactories.Add(GroupManager.GetTypeName(), GroupManager)
            Next
        End Sub

        Public Shared Function GetGroup(UIG As UIGroup) As UrlGroup
            Return ManagerFactories(UIG.Type).fromUIGroup(UIG)
        End Function

        Public Shared Function GetGroupManager(Of T As UrlGroup)() As IFUPGroupManager
            Return ManagerFactories(GetType(T).Name)
        End Function

        Public Shared Function GetGroupManager(ug As UrlGroup) As IFUPGroupManager
            Return ManagerFactories(ug.GetType().Name)
        End Function
    End Class

End Namespace